#include<iostream>
using namespace std;
struct Tree
{
	int key,ltag,rtag;
	Tree *leftchild,*rightchild;
};
Tree *root;
void createtree(Tree*nil)
{
	int n;
	cin>>n;
	if(n==0)
	{
		nil=NULL;
		return;
	}
	nil=new Tree;
	nil->key=n;
	createtree(nil->leftchild);
	createtree(nil->rightchild);
}
int BinaryTreeSize(Tree* root)
{	
	return root == NULL ? 0 : BinaryTreeSize(root->leftchild) + BinaryTreeSize(root->rightchild) + 1;
}
int TreeSize(Tree*nil)
{
	if(nil==NULL)return 0;
	else
	{
		return TreeSize(nil->leftchild)+TreeSize(nil->rightchild)+1;
	}
}
void visit(Tree*nil)
{
	cout<<nil->key<<endl;
}
void inordertraverse(Tree*nil)
{
	if(nil==NULL)return;
	else
	{
	visit(nil);
	inordertraverse(nil->leftchild);
	inordertraverse(nil->rightchild);
	}
}

int main()
{
	createtree(root);
	//inordertraverse(root);
	int t=BinaryTreeSize(root);
	cout<<t;
	return 0;
}
